home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
NewsTicker.sit
/
NewsTicker
/
source code
/
WindowStuff
/
TickerWindowHandler.cp
< prev
next >
Wrap
Text File
|
1997-06-26
|
25KB
|
1,068 lines
/*------------------------------------------------------------------------------
#
# NewsTicker, my Hack for 1997
#
# TickerWindowHandler.cp - This handles our TSM floating window that shows
# the scrolling list of news
#
------------------------------------------------------------------------------*/
#include <TextServices.h>
#include <icons.h>
#include "TickerGlobals.h" /* bring in all the #defines and structures for NewsTicker */
#include "TickerWindowHandler.h"
#include "jGNELib.h"
#include "TickerReadHeadlines.h"
void DrawMyWindow(WindowPtr aWind, sMyDataPtr gGlobalsPtr);
pascal Boolean CalledHandleAnEvent(EventRecord* event, sMyDataPtr gGlobalsPtr);
void BuildTheRects( sMyDataPtr gGlobalsPtr );
void PlotTheItems(sMyDataPtr gGlobalsPtr, Rect* therect);
static void ShowTheRect(Rect* therect)
{
Rect visrect;
RgnHandle rgn;
short thetitlebarheight = 12; //size of the title bar of our menu
rgn = GetGrayRgn();
visrect =( *(rgn))->rgnBBox;
if (therect->bottom > visrect.bottom +2)
{
OffsetRect(therect, 0, visrect.bottom +2 - therect->bottom );
}
if (therect->top < visrect.top + thetitlebarheight)
{
OffsetRect(therect, 0, visrect.top + thetitlebarheight - therect->top);
}
if (therect->right > visrect.right +2)
{
OffsetRect(therect, visrect.right +2 - therect->right, 0);
}
if (therect->left < visrect.left - 2)
{
OffsetRect(therect, visrect.left - 2 - therect->left, 0);
}
}
static void SetTheClick(DialogPtr d, short whichitem, Boolean theval)
{
short dtype;
Handle ditem;
Rect rview;
short itemhit;
GetDialogItem(d,whichitem,&dtype,&ditem,&rview);
if (theval)
{
SetControlValue((ControlHandle)ditem, 1);
}
else
{
SetControlValue((ControlHandle)ditem, 0);
}
}
static void BlinkButton(DialogPtr theDialog,
short btnNumber)
{
Handle itemHandle;
short itemType;
Rect itemRect;
long ignoreLong;
GetDialogItem(theDialog, btnNumber, &itemType, &itemHandle, &itemRect);
HiliteControl((ControlHandle)itemHandle, true);
Delay(7, &ignoreLong);
HiliteControl((ControlHandle)itemHandle, false);
}
static pascal void MyDialogItem(DialogPtr thedialog, short itemnum)
{
short dtype;
Handle ditem;
Rect rview;
RgnHandle temprgn;
GetDialogItem(thedialog,itemnum,&dtype,&ditem,&rview);
if (itemnum==24)
{
MoveTo(rview.left, rview.top);
LineTo(rview.right-1, rview.top);
MoveTo(rview.left, rview.top+3);
LineTo(rview.right-1, rview.top+3);
}
if (itemnum==25)
{
PenSize(3,3);
FrameRoundRect(&rview, 16, 16);
PenSize(1,1);
}
}
static Boolean NoteDialogKey(EventRecord *macEvent,
short *itemHit,
DialogPtr pDialog)
{
#define kDelay 7
char theChar;
Boolean OKisOK;
short itemType;
ControlHandle itemHandle;
Rect itemRect;
switch (macEvent->message & charCodeMask)
{
case 0x03: // enter key
case 0x0D: // return key
GetDialogItem(pDialog, 1, &itemType, &((Handle)itemHandle), &itemRect);
if ((*itemHandle)->contrlHilite)
{
macEvent->what = 0;
return false;
}
else
{
BlinkButton(pDialog, 1);
*itemHit = 1;
return true;
}
case 0x1B: // escape key
BlinkButton(pDialog, 2);
*itemHit = 2;
return true;
default:
return false;
}
}
static pascal Boolean NoteDialogEventFilter(DialogPtr pDialog,
EventRecord *macEvent,
short *itemHit)
{
switch (macEvent->what)
{
case keyDown:
case autoKey:
return NoteDialogKey(macEvent, itemHit, pDialog);
default:
return false;
}
}
Boolean DoConfigure ( void )
{
DialogPtr mydialog;
short dtype;
Handle ditem;
Rect rview;
short itemhit;
Point mypoint;
sPreferences tempprefs;
Rect dataBounds;
Cell cSize;
Cell theCell;
CursHandle thewatch;
short i;
OSErr theerr;
short refnum;
long count;
short index;
Str255 tempstr;
ModalFilterUPP OurFilterUPP;
UserItemUPP OurItemUPP;
OurFilterUPP = NewModalFilterProc(NoteDialogEventFilter);
OurItemUPP = NewUserItemProc(MyDialogItem); //outline the OK button
if (gOurGlobals)
{
HideWindow(gOurGlobals->gMyWind);
gOurGlobals->IsWindowShowing = false;
}
BlockMove(&gThePrefs, &tempprefs, sizeof(sPreferences));
mydialog=GetNewDialog(130,nil,(WindowPtr)-1);
SetTheClick(mydialog, 3, tempprefs.hideIfEmpty);
SetTheClick(mydialog, 4, tempprefs.scrollingSpeed==1);
SetTheClick(mydialog, 5, tempprefs.scrollingSpeed==2);
SetTheClick(mydialog, 6, tempprefs.scrollingSpeed==4);
SetTheClick(mydialog, 7, tempprefs.DoReadApple);
SetTheClick(mydialog, 8, tempprefs.DoReadCNN);
SetTheClick(mydialog, 9, tempprefs.DoReadNews);
SetTheClick(mydialog, 26, tempprefs.JustShowFirstThree);
GetDialogItem(mydialog,24,&dtype,&ditem,&rview);
SetDialogItem(mydialog,24,dtype,(Handle)OurItemUPP,&rview);
GetDialogItem(mydialog,25,&dtype,&ditem,&rview);
SetDialogItem(mydialog,25,dtype,(Handle)OurItemUPP,&rview);
for (index = 0; index<numWebPages; index++) // copy the entries off
{
GetDialogItem(mydialog,10+index,&dtype,&ditem,&rview);
SetDialogItemText(ditem, tempprefs.WebPageAddress[index]);
}
InitCursor();
do
{
ModalDialog(OurFilterUPP, &itemhit);
switch(itemhit)
{
case 1: //save off the text items
for (index = 0; index<numWebPages; index++) // copy the entries off
{
GetDialogItem(mydialog,10+index,&dtype,&ditem,&rview);
GetDialogItemText(ditem, tempprefs.WebPageAddress[index]);
if (!tempprefs.WebPageAddress[index][0])
{
PLstrcpy(tempprefs.WebPageLastDate[index], "\p");
tempprefs.WebPageDisplay[index] = false;
}
else if (!tempprefs.WebPageLastDate[index][0]) //must be a new guy
{
PLstrcpy(tempprefs.WebPageLastDate[index], "\pNew Entry");
tempprefs.WebPageDisplay[index] = true;
}
}
break;
case 3:
tempprefs.hideIfEmpty = !tempprefs.hideIfEmpty;
SetTheClick(mydialog, 3, tempprefs.hideIfEmpty);
break;
case 4:
case 5:
case 6:
switch (itemhit)
{
case 4:
tempprefs.scrollingSpeed = 1;
break;
case 5:
tempprefs.scrollingSpeed = 2;
break;
case 6:
tempprefs.scrollingSpeed = 4;
break;
}
SetTheClick(mydialog, 4, tempprefs.scrollingSpeed==1);
SetTheClick(mydialog, 5, tempprefs.scrollingSpeed==2);
SetTheClick(mydialog, 6, tempprefs.scrollingSpeed==4);
break;
case 7:
tempprefs.DoReadApple = !tempprefs.DoReadApple;
SetTheClick(mydialog, 7, tempprefs.DoReadApple);
break;
case 8:
tempprefs.DoReadCNN = !tempprefs.DoReadCNN;
SetTheClick(mydialog, 8, tempprefs.DoReadCNN);
break;
case 9:
tempprefs.DoReadNews = !tempprefs.DoReadNews;
SetTheClick(mydialog, 9, tempprefs.DoReadNews);
break;
case 26:
tempprefs.JustShowFirstThree = !tempprefs.JustShowFirstThree;
SetTheClick(mydialog, 26, tempprefs.JustShowFirstThree);
break;
}
}
while (itemhit>2);
DisposeRoutineDescriptor(OurFilterUPP);
DisposeRoutineDescriptor(OurItemUPP);
DisposeDialog(mydialog);
if (itemhit==1)
{
BlockMove(&tempprefs, &gThePrefs, sizeof(sPreferences));
theerr = FSpCreate(&gPrefsSpec, 'DATA', 'DATA', smSystemScript);
theerr = FSpOpenDF(&gPrefsSpec, 0, &refnum);
if (theerr==noErr)
{
count = sizeof(gThePrefs);
theerr = FSWrite(refnum, &count, &gThePrefs);
theerr = FSClose(refnum);
}
if (gOurGlobals)
{
FillTheHeadlines(gOurGlobals);
BuildTheRects(gOurGlobals);
CalcOffsets ( gOurGlobals );
}
}
if (gOurGlobals)
{
ShowWindow(gOurGlobals->gMyWind);
gOurGlobals->IsWindowShowing = true;
}
return (itemhit==1);
}
static void ScrollLeft ( sMyDataPtr gGlobalsPtr )
{
GrafPtr tempport;
RgnHandle updateRgn;
short i;
Rect RedrawRect;
short amountToScroll;
amountToScroll = gThePrefs.scrollingSpeed;
if (gGlobalsPtr->sCurrentCommentRect.right - gGlobalsPtr->sCurrentCommentRect.left
> gGlobalsPtr->MsgWidth)
{
return;
}
GetPort(&tempport);
SetPort(gGlobalsPtr->gMyWind);
updateRgn = NewRgn();
ScrollRect(&gGlobalsPtr->sCurrentCommentRect, - amountToScroll, 0, updateRgn);
InvalRgn(updateRgn);
DisposeRgn(updateRgn);
RedrawRect =gGlobalsPtr->sCurrentCommentRect;
RedrawRect.left = RedrawRect.right - amountToScroll;
for (i = 0; i < gGlobalsPtr->MsgCount; i++)
{
gGlobalsPtr->theHeadlines[i].leftside -= amountToScroll;
if (gGlobalsPtr->theHeadlines[i].leftside+gGlobalsPtr->theHeadlines[i].width<0)
{
gGlobalsPtr->theHeadlines[i].leftside+= (gGlobalsPtr->MsgWidth );
if (gGlobalsPtr->theHeadlines[i].leftside<RedrawRect.left)
{
RedrawRect.left = gGlobalsPtr->theHeadlines[i].leftside;
}
}
}
// Assume we just scrolled the little bit and it's all that needs updating
PlotTheItems(gGlobalsPtr, &RedrawRect);
ValidRect(&RedrawRect);
SetPort(tempport);
}
void CalcOffsets ( sMyDataPtr gGlobalsPtr )
{
short i;
short currleft = 0;
short width = 0;
SetPort(gGlobalsPtr->gMyWind);
TextSize(9);
TextFont(applFont);
TextFace(0);
gGlobalsPtr->MsgWidth = 0;
for (i = 0; i < gGlobalsPtr->MsgCount; i++)
{
gGlobalsPtr->theHeadlines[i].leftside = currleft;
width = StringWidth(gGlobalsPtr->theHeadlines[i].Subject) + 30;
gGlobalsPtr->theHeadlines[i].width = width;
currleft += width;
gGlobalsPtr->MsgWidth += width;
}
if ((gThePrefs.hideIfEmpty) && (gGlobalsPtr->MsgWidth == 0))
{
HideWindow(gGlobalsPtr->gMyWind);
gGlobalsPtr->IsWindowShowing = false;
}
else
{
ShowWindow(gGlobalsPtr->gMyWind);
gGlobalsPtr->IsWindowShowing = true;
}
//EraseRect(&gGlobalsPtr->gMyWind->portRect);
InvalRect(&gGlobalsPtr->gMyWind->portRect);
}
void InitWHandler( void )
{
Handle h;
OSErr theerr;
short vref;
long dirID;
short refnum;
long count;
short index;
gThePrefs.hideIfEmpty = true;
gThePrefs.scrollingSpeed = 2;
SetRect(&gThePrefs.winrect, 0, 0, 0, 0);
gThePrefs.DoReadNews = true;
gThePrefs.DoReadApple = true;
gThePrefs.DoReadCNN = true;
for (index=0; index<numWebPages; index++)
{
gThePrefs.WebPageAddress[index][0] = 0; //zero the strings
gThePrefs.WebPageLastDate[index][0] = 0;
gThePrefs.WebPageDisplay[index] = false;
}
gThePrefs.JustShowFirstThree = true;
theerr = FindFolder(kOnSystemDisk, kPreferencesFolderType, false, &vref, &dirID);
theerr = FSMakeFSSpec(vref, dirID, "\pNewsTicker.prefs", &gPrefsSpec);
theerr = FSpOpenDF(&gPrefsSpec, 0, &refnum);
if (theerr==noErr)
{
count = sizeof(gThePrefs);
theerr = FSRead(refnum, &count, &gThePrefs);
theerr = FSClose(refnum);
}
else
{
if (!DoConfigure())
ExitToShell();
}
InitjGNEProcLib();
gOurGlobals = (sMyDataPtr) NewPtrSysClear(sizeof(sMyData));
if (!gOurGlobals)
{
ExitToShell();
}
gOurGlobals->gWindowIsMinimized = false;
gOurGlobals->gDoQuit = false;
gOurGlobals->MsgToOpen = -1;
InitInternetConfig();
FillTheHeadlines(gOurGlobals);
CreateMyWindow();
HookjGNE((long)&CalledHandleAnEvent, (long)gOurGlobals);
gOurGlobals->WhenToScroll = TickCount();
}
void CloseWHandler ( void )
{
OSErr anErr;
short refnum;
long count;
SetPort(gOurGlobals->gMyWind);
gThePrefs.winrect = gOurGlobals->sPortRect;
LocalToGlobal( (Point*) (&gThePrefs.winrect.top));
LocalToGlobal( (Point*) (&gThePrefs.winrect.bottom));
anErr = FSpCreate(&gPrefsSpec, 'DATA', 'DATA', smSystemScript);
anErr = FSpOpenDF(&gPrefsSpec, 0, &refnum);
if (anErr==noErr)
{
count = sizeof(gThePrefs);
anErr = FSWrite(refnum, &count, &gThePrefs);
anErr = FSClose(refnum);
}
UnHookjGNE();
anErr = CloseServiceWindow(gOurGlobals->gMyWind);
gOurGlobals->gMyWind=nil;
DisposePtr(gOurGlobals->wStorage);
DisposePtr((Ptr)gOurGlobals);
}
void JustHandleWindow( void )
{
short whichmsg;
if (!(gOurGlobals->gMyWind))
{
return;
}
if (!gOurGlobals->IsWindowShowing)
{
return;
}
if (gOurGlobals->MsgToOpen!=-1)
{
whichmsg = gOurGlobals->MsgToOpen;
gOurGlobals->MsgToOpen = -1;
OpenItem(gOurGlobals, whichmsg);
}
if ((gOurGlobals->WhenToScroll+2<TickCount() ) && gOurGlobals->IsWindowShowing)
{
ScrollLeft(gOurGlobals);
gOurGlobals->WhenToScroll = TickCount();
}
if ((!EmptyRgn(((WindowPeek)(gOurGlobals->gMyWind))->updateRgn))&& gOurGlobals->IsWindowShowing)
{
SetZone(SystemZone());
BeginUpdate(gOurGlobals->gMyWind);
DrawMyWindow(gOurGlobals->gMyWind, gOurGlobals);
EndUpdate(gOurGlobals->gMyWind);
SetZone(ApplicationZone());
}
if (gOurGlobals->gDoQuit)
{
gDoneFlag = false;
gOurGlobals->gDoQuit = false;
}
}
static void DoMyZoom(sMyDataPtr gGlobalsPtr)
{
GrafPtr window;
Point aPoint;
Rect visrect;
RgnHandle rgn;
gGlobalsPtr->gDoZoom = false;
rgn = GetGrayRgn();
visrect =( *(rgn))->rgnBBox;
GetPort(&window);
SetPort(gGlobalsPtr->gMyWind);
aPoint.h = 0;
aPoint.v = 0;
LocalToGlobal(&aPoint);
if (gGlobalsPtr->gWindowIsMinimized)
{
gGlobalsPtr->gWindowIsMinimized = false;
ShowHide(gGlobalsPtr->gMyWind, false);
SizeWindow(gGlobalsPtr->gMyWind,
gGlobalsPtr->sPortRect.right - gGlobalsPtr->sPortRect.left,
gGlobalsPtr->sPortRect.bottom - gGlobalsPtr->sPortRect.top,
true);
if ( aPoint.h-(gGlobalsPtr->sPortRect.right - gGlobalsPtr->sPortRect.left - 100) > visrect.left)
{
MoveWindow(gGlobalsPtr->gMyWind,
aPoint.h-(gGlobalsPtr->sPortRect.right - gGlobalsPtr->sPortRect.left - 100),
aPoint.v,
false);
}
ShowHide(gGlobalsPtr->gMyWind, true);
BuildTheRects(gGlobalsPtr);
CalcOffsets ( gGlobalsPtr );
}
else
{
gGlobalsPtr->gWindowIsMinimized = true;
ShowHide(gGlobalsPtr->gMyWind, false);
SizeWindow(gGlobalsPtr->gMyWind,
100,
25,
true);
MoveWindow(gGlobalsPtr->gMyWind,
aPoint.h+(gGlobalsPtr->sPortRect.right - gGlobalsPtr->sPortRect.left - 100),
aPoint.v,
false);
ShowHide(gGlobalsPtr->gMyWind, true);
BuildTheRects(gGlobalsPtr);
CalcOffsets ( gGlobalsPtr );
}
SetPort(window);
}
void PollWHandler (Point where)
{
if (!(gOurGlobals->gMyWind))
{
return;
}
if (gOurGlobals->gDoZoom)
{
DoMyZoom(gOurGlobals);
}
if (gOurGlobals->gDidResize)
{
gOurGlobals->gDidResize = false;
BuildTheRects(gOurGlobals);
CalcOffsets ( gOurGlobals );
}
JustHandleWindow();
MaybeReload(gOurGlobals);
}
void BuildTheRects( sMyDataPtr gGlobalsPtr )
{
Rect tempPortrect;
if (!gGlobalsPtr->gWindowIsMinimized)
{
gGlobalsPtr->sPortRect = gGlobalsPtr->gMyWind->portRect;
gGlobalsPtr->sGrowRect.left = gGlobalsPtr->sPortRect.right-5;
gGlobalsPtr->sGrowRect.right = gGlobalsPtr->sPortRect.right;
gGlobalsPtr->sGrowRect.top = gGlobalsPtr->sPortRect.bottom - 5;
gGlobalsPtr->sGrowRect.bottom = gGlobalsPtr->sPortRect.bottom;
}
else
{
SetRect(&gGlobalsPtr->sGrowRect, 0, 0, 0, 0);
}
tempPortrect = gGlobalsPtr->gMyWind->portRect;
gGlobalsPtr->sCurrentCommentRect.left = tempPortrect.left+8;
gGlobalsPtr->sCurrentCommentRect.top =
(tempPortrect.top + tempPortrect.bottom) / 2 -8;
gGlobalsPtr->sCurrentCommentRect.bottom = gGlobalsPtr->sCurrentCommentRect.top+16;
gGlobalsPtr->sCurrentCommentRect.right = tempPortrect.right-8;
}
void CreateMyWindow ( void )
{
OSErr anErr;
WindowPtr thewindow;
Rect therect;
Handle h;
Str255 tempstr;
gOurGlobals->gMyWind = nil;
if (!(gOurGlobals->gMyWind))
{
SetZone(SystemZone());
if (EmptyRect(&gThePrefs.winrect))
{
h = GetResource('WIND', 128);
if (!h)
{
return;
}
BlockMove(*h, &therect, sizeof(therect));
}
else
{
therect = gThePrefs.winrect;
}
ShowTheRect(&therect);
gOurGlobals->wStorage = NewPtr(sizeof(WindowRecord));
if (!gOurGlobals->wStorage) return;
if (GetResource('WDEF', 124))
{
anErr = NewServiceWindow(gOurGlobals->wStorage, &therect,"\pNewsTicker",
true,124*16+5,(WindowPtr)-1,true,
nil,/*(ComponentInstance)kCurrentProcess*/ &thewindow);
}
else
{
anErr = NewServiceWindow(gOurGlobals->wStorage, &therect,"\pNewsTicker",
true,zoomNoGrow /*floatZoomProc*/, (WindowPtr)-1,true,
nil,/*(ComponentInstance)kCurrentProcess*/ &thewindow);
}
SetPort(thewindow);
gOurGlobals->gMyWind = thewindow;
HiliteWindow(thewindow,true);
BuildTheRects(gOurGlobals);
CalcOffsets(gOurGlobals);
SetZone(ApplicationZone());
}
}
void CloseMyWindow (WindowPtr aWind)
{
CloseWindow(aWind);
}
static void MyTETextBox(unsigned char* thetext, long textlength, Rect* therect, short thejust)
{
FontInfo info;
short fontheight;
short y;
short rectwidth;
short length2;
short theoffset = 0;
char thechar;
Boolean endofline;
short lastspace;
GetFontInfo(&info);
fontheight = info.ascent+info.descent+info.leading;
y = therect->top+info.ascent;
rectwidth = therect->right - therect->left;
do
{
if (theoffset>=textlength)
{
return;
}
length2 = 0;
endofline = false;
lastspace = 0;
do
{
thechar = *(Ptr)((long)thetext+theoffset+length2);
if (thechar==' ')
{
lastspace = length2;
}
if (thechar==13)//end of line
{
endofline = true;
}
length2++;
}
while ((TextWidth(thetext, theoffset, length2)<rectwidth) && (!endofline) && (length2+theoffset<textlength));
if ((lastspace>0) && (TextWidth(thetext, theoffset, length2)>=rectwidth))
{
length2 = lastspace;
}
MoveTo(therect->left, y);
DrawText(thetext, theoffset, length2);
theoffset += length2;
y+=fontheight;
}
while ((theoffset < textlength) && ( y<therect->bottom));
if (theoffset<textlength)
{
DrawChar('…');
}
}
static void PlotColorPtr(short wDepth, short wFaceSize,
Rect* DestRect, Ptr p)
{
PixMapHandle hPixMap;
GrafPtr pCurPort;
wDepth=8; wFaceSize=16;
hPixMap=NewPixMap();
MoveHHi((Handle)hPixMap);
HLock((Handle)hPixMap);
(**hPixMap).hRes=0x0480000;
(**hPixMap).vRes=0x0480000;
(**hPixMap).pixelType=0;
(**hPixMap).planeBytes=0;
(**hPixMap).bounds.top=0;
(**hPixMap).bounds.left=0;
(**hPixMap).bounds.bottom=wFaceSize;
(**hPixMap).bounds.right=wFaceSize;
(**hPixMap).pixelSize=wDepth;
(**hPixMap).cmpCount=wDepth;
(**hPixMap).rowBytes=((wDepth*wFaceSize) / 8)+0x08000;
(**hPixMap).baseAddr=(Ptr)p;
DisposeCTable((**hPixMap).pmTable);
(**hPixMap).pmTable=GetCTable(wDepth);
GetPort(&pCurPort);
CopyBits((BitMap*)(*hPixMap), &(pCurPort->portBits), &(**hPixMap).bounds,
DestRect,srcCopy,nil);
(**hPixMap).baseAddr=nil;
HUnlock((Handle)hPixMap);
DisposePixMap(hPixMap);
}
/* Define TopLeft and BotRight macros for convenience. Notice the implicit
dependency on the ordering of fields within a Rect */
#define TopLeft(aRect) (* (Point *) &(aRect).top)
#define BotRight(aRect) (* (Point *) &(aRect).bottom)
static short ColorRectDepth(Rect* therect)
{
long response;
Rect r2;
GDHandle thegd;
if (Gestalt(gestaltQuickdrawVersion,&response)==noErr)
{
if (response>=gestalt8BitQD)
{
r2 = *therect;
LocalToGlobal((Point*)(&r2.top));
LocalToGlobal((Point*)(&r2.bottom));
thegd = GetMaxDevice(&r2);
if (thegd)
{
return (**(**thegd).gdPMap).pixelSize;
}
}
}
return 1; //assume black and white
}
static void PlotBWPtr(short wFaceSize,
Rect* DestRect, Ptr p)
{
GrafPtr pCurPort;
BitMap mybitmap;
mybitmap.bounds.top = 0;
mybitmap.bounds.left = 0;
mybitmap.bounds.bottom = wFaceSize;
mybitmap.bounds.right = wFaceSize;
mybitmap.rowBytes = wFaceSize / 8;
mybitmap.baseAddr = p;
GetPort(&pCurPort);
CopyBits(&mybitmap, &(pCurPort->portBits), &mybitmap.bounds, DestRect, 0, nil);
}
void PlotTheItems(sMyDataPtr gGlobalsPtr, Rect* therect)
{
short i;
short leftedge;
short rightedge;
CIconHandle theicon = nil;
Rect temprect;
if (therect->left < gGlobalsPtr->sCurrentCommentRect.left)
{
therect->left=gGlobalsPtr->sCurrentCommentRect.left;
}
ClipRect(therect);
EraseRect(therect);
for (i = 0; i < gGlobalsPtr->MsgCount; i++)
{
leftedge = gGlobalsPtr->sCurrentCommentRect.left + gGlobalsPtr->theHeadlines[i].leftside;
rightedge = leftedge + gGlobalsPtr->theHeadlines[i].width;
if ( ( leftedge < therect->right ) &&
( rightedge > therect->left ) )
{
if ( leftedge+20 > therect->left ) // Only plot icon if it'll show
{
theicon = GetCIcon(gGlobalsPtr->theHeadlines[i].cicnResID);
if (theicon)
{
temprect.left = leftedge;
//temprect.right = leftedge+16;
temprect.right = leftedge+ (**theicon).iconBMap.bounds.right - (**theicon).iconBMap.bounds.left;
temprect.bottom = (*therect).bottom;
temprect.top = (*therect).bottom-16;
PlotCIcon(&temprect, theicon);
DisposeCIcon(theicon);
}
}
MoveTo(leftedge+22, (*therect).bottom-4);
DrawString(gGlobalsPtr->theHeadlines[i].Subject);
}
}
ClipRect(&gGlobalsPtr->gMyWind->portRect);
}
void DrawMyWindow(WindowPtr aWind, sMyDataPtr gGlobalsPtr)
{
RGBColor tempcolor;
RgnHandle temprgn;
Rect temprect;
short h;
GrafPtr tempport;
CIconHandle theicon = nil;
Str255 tempstr = "\pNot logged in";
short leftedge;
short rightedge;
short i;
PicHandle aPicH;
GetPort(&tempport);
SetPort(aWind);
ClipRect(&aWind->portRect);
if (ColorRectDepth(&aWind->portRect)<8) //determine what kind of gray to use
{
FillRect(&aWind->portRect,&qd.gray);
}
else
{
aPicH = GetPicture(129);
DrawPicture(aPicH, &aWind->portRect);
}
TextSize(9);
TextFont(applFont);
TextFace(0);
temprect = gGlobalsPtr->sCurrentCommentRect;
InsetRect(&temprect, -1, -1);
FrameRect(&temprect);
InsetRect(&temprect, 1, 1);
PlotTheItems(gGlobalsPtr, &temprect);
PaintRect(&gGlobalsPtr->sGrowRect);
SetPort(tempport);
}
static long abs(long theval)
{
if (theval<0)
{
return - theval;
}
else
{
return theval;
}
}
static void MyClick(Point where, sMyDataPtr gGlobalsPtr)
{
Rect temprect;
Point thespot;
long aLong;
short i;
short leftedge;
short rightedge;
unsigned long now;
SetPort(gGlobalsPtr->gMyWind);
thespot = where;
GlobalToLocal(&thespot);
if (PtInRect(thespot, &gGlobalsPtr->sGrowRect))
{
SetRect(&temprect, 65, 25, 32767, 25);
aLong = GrowWindow(gGlobalsPtr->gMyWind, where, &temprect);
SizeWindow(gGlobalsPtr->gMyWind,
LoWord(aLong), HiWord(aLong), true);
gGlobalsPtr->gDidResize = true;
}
else if (PtInRect(thespot, &gGlobalsPtr->sCurrentCommentRect))
{
for (i = 0; i < gGlobalsPtr->MsgCount; i++)
{
leftedge = gGlobalsPtr->sCurrentCommentRect.left + gGlobalsPtr->theHeadlines[i].leftside;
rightedge = leftedge + gGlobalsPtr->theHeadlines[i].width;
if ((thespot.h>leftedge)&&(thespot.h<rightedge))
{
GetDateTime(&now);
if ((now - gGlobalsPtr->WhenLastClick>GetDblTime())
|| ( abs(gGlobalsPtr->LastClick.h-thespot.h)>4)
|| ( abs(gGlobalsPtr->LastClick.v-thespot.v)>4))
{
gGlobalsPtr->LastClick = thespot;
gGlobalsPtr->WhenLastClick = now;
return;
}
else gGlobalsPtr->MsgToOpen = i;
}
}
}
}
typedef pascal long (*GNEHandlerActionProcPtr)(short varCode, WindowRef theWindow,
short message, Point where);
#if GENERATINGCFM
enum
{
uppMyWindowDefProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(long)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
};
typedef UniversalProcPtr WindowHandlerUPP;
#define NewWindowHandlerUPP(userRoutine) \
(WindowHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppMyWindowDefProcInfo, (ISAType)kM68kISA)
#define CallWindowHandlerProc(userRoutine, param1, param2, param3, param4) \
CallUniversalProc((UniversalProcPtr)(userRoutine), uppMyWindowDefProcInfo, param1, param2, param3, param4)
#else
typedef GNEHandlerActionProcPtr WindowHandlerUPP;
#define NewWindowHandlerUPP(userRoutine) ((WindowHandlerUPP) (userRoutine))
#define CallWindowHandlerProc(userRoutine, param1, param2, param3, param4) \
(*(userRoutine)) ((param1), (param2), (param3), (param4))
#endif
static short CheckOneWindow(WindowPtr thewindow, Point where)
{
Handle h;
short thevariant;
short theresult;
WindowHandlerUPP thehandler;
h = ((WindowPeek)thewindow)->windowDefProc;
HLock(h);
thevariant = GetWVariant(thewindow);
thehandler = NewWindowHandlerUPP(*(GNEHandlerActionProcPtr)(*h));
theresult = CallWindowHandlerProc(thehandler, thevariant, thewindow, wHit, where);
DisposeRoutineDescriptor(thehandler);
HUnlock(h);
return theresult;
}
pascal Boolean CalledHandleAnEvent(EventRecord* event, sMyDataPtr gGlobalsPtr)
{
short part;
Boolean hit;
Rect temprect;
GrafPtr savePort;
switch ( event->what )
{
case mouseDown:
part = CheckOneWindow(gGlobalsPtr->gMyWind, event->where);
switch ( part ) {
case wInContent:
GetPort(&savePort);
MyClick(event->where, gGlobalsPtr);
SetPort(savePort);
event->what = 0;
return true;
break;
case wInDrag: /* pass screenBits.bounds to get all gDevices */
SetRect(&temprect, -32767, -32767, 32767, 32767);
DragWindow(gGlobalsPtr->gMyWind, event->where, &temprect);
event->what = 0;
return true;
break;
case wInGoAway:
hit = TrackGoAway(gGlobalsPtr->gMyWind, event->where);
if (hit )
{
gGlobalsPtr->gDoQuit = true;
}
event->what = 0;
return true;
break;
case wInZoomIn:
case wInZoomOut:
hit = TrackBox(gGlobalsPtr->gMyWind, event->where ,part+2);
if (hit)
{
gGlobalsPtr->gDoZoom = true;
}
event->what = 0;
return true;
break;
}
break;
}
return false;
}